/*-
 * Copyright (c) 2009-2010 David Forsythe.
 * See LICENSE file for license details.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <getopt.h>

#include <pkg.h>
#include <pkg_freebsd.h>

#include "pkg_dump.h"

int
main(int argc, char **argv)
{
        /* From pkg.h */
        struct pkg_database *db;
        struct pkg *p;

        /* From pkg_freebsd.h */
        struct pkg_file f;
        struct pkg_dependency d;
        struct pkg_conflict c;

        (void)argc;
        (void)argv;

        db = pkg_freebsd_database_create();
        p = pkg_freebsd_create();

        pkg_database_open(db, "/var/db/pkg", 0);
        
        while (pkg_database_get_next_pkg(db, p, 
                FBSD_METACODE_REQUIRED_BY) == PKG_OK) {
                printf("Package Name: %s\n", pkg_freebsd_get_name(p));
                printf("\tOrigin: %s\n", pkg_freebsd_get_origin(p));
                printf("\tFiles:\n");
                while (pkg_freebsd_get_next_file(p, &f) == PKG_OK) {
                        printf("\t\t%s/%s\n",
                                pkg_freebsd_file_get_prefix(&f),
                                pkg_freebsd_file_get_pathname(&f));
                        printf("\t\t\tMD5: %s\n", pkg_freebsd_file_get_hash(&f));
                        printf("\t\t\tIgnored: %s\n", 
                                (pkg_freebsd_file_get_ignored(&f) ? 
                                "TRUE" :
                                "FALSE"));
                }
                printf("\tDependencies:\n");
                while (pkg_freebsd_get_next_dependency(p, &d) == PKG_OK) {
                        printf("\t\t%s\n", pkg_freebsd_dependency_get_name(&d));
                        printf("\t\t\tOrigin: %s\n",
                                pkg_freebsd_dependency_get_origin(&d));
                }
                printf("\tConflicts:\n");
                while (pkg_freebsd_get_next_conflict(p, &c) == PKG_OK) {
                        printf("\t\t%s\n", pkg_freebsd_conflict_get_expression(&c));
                }
        }
        pkg_clear(p);
        pkg_release(p);
        pkg_database_close(db);
        pkg_database_release(db);
}


